package any.functor;

import java.util.Map.Entry;

import any.Any;
import any.ImmutableAny;
import any.functor.interfaces.Closure;
import any.functor.interfaces.Predicate;

public abstract class BaseAnyClosure implements PredicatableClosure<Entry<String, ? extends ImmutableAny>, Any> {

    private final String description;

	public BaseAnyClosure(String description) {
		this.description = description;
    }
	
	protected Predicate<? super Entry<String, ? extends ImmutableAny>> predicate;

	public Closure<Any> select(Predicate<? super Entry<String, ? extends ImmutableAny>> predicate) {
		this.predicate = predicate;
		return this;
	}
	
	public Closure<Any> filter(Predicate<? super Entry<String, ? extends ImmutableAny>> predicate) {
		if (predicate != null) {
			predicate = Predicates.not(predicate);
		} else {
			this.predicate = null;			
		}
		return this;
	}
	
	@Override
	public String toString() {
	    return description;
	}
	
}
